package com.zyj.delayqueue.norely;

import java.time.Duration;
import java.util.concurrent.DelayQueue;
import java.util.concurrent.Delayed;
import java.util.logging.Logger;

/**
 * 没有其他任何依赖, 直接使用的JDK提供的DelayQueue实现
 */
public class PlainDelayQueue {
    public static final Logger LOGGER = Logger.getLogger(PlainDelayQueue.class.getName());

    public static void main(String[] args) throws InterruptedException {
        b();
    }

    //自己搞个线程
    public static void a() throws InterruptedException {
        DelayQueue delayQueue = new DelayQueue();
        delayQueue.offer(DelayedTask.build(Duration.ofSeconds(10), 10));
        delayQueue.offer(DelayedTask.build(Duration.ofSeconds(2), 2));
        delayQueue.offer(DelayedTask.build(Duration.ofSeconds(4), 4));
        delayQueue.offer(DelayedTask.build(Duration.ofSeconds(9), 9));
        delayQueue.offer(DelayedTask.build(Duration.ofSeconds(3), 3));
        delayQueue.offer(DelayedTask.build(Duration.ofSeconds(7), 7));
        delayQueue.offer(DelayedTask.build(Duration.ofSeconds(6), 6));
        delayQueue.offer(DelayedTask.build(Duration.ofSeconds(8), 8));
        delayQueue.offer(DelayedTask.build(Duration.ofSeconds(1), 1));
        delayQueue.offer(DelayedTask.build(Duration.ofSeconds(5), 5));
        while (true) {
            Delayed take = delayQueue.take();
            LOGGER.info(take.toString());
        }
    }

    //用线程池执行
    public static void b() throws InterruptedException {
    }
}
